window.onload = function(){
    layui.use(['jquery','form','layer'],function(){
        var $ = layui.jquery;

        $(".save-admin").on("click",function(){
            var menuName=$(":input[name='username']").val();
            var menuAddr=$(":input[name='email']").val();
            var menuPswd=$(":input[name='password']").val();
            var player=$("input[type=checkbox]:checked");
    
            var form = $("form").serialize()
    
            if(menuName==""||menuAddr==""||menuPswd==""||player.length==0){
                Utils.layer.msg("请完善信息!")
            }else{
                $.ajax({
                    url:"/admin/add-admin",
                    type:"post",
                    data:form,
                    dataType:"json",
                    success:function(data){
                        if(data.code==200){
                            Utils.layer.msg(data.msg);
                            setTimeout(function(){
                                location.href="/admin/index";
                            },1200)
                        }else{
                            Utils.layer.msg(data.msg);
                        }
                    }
                })
            }
        })
    })
}